<?php
class App_Model_Logs
{
	private $dir;
	private $login;
	private $date;
	
	public function __construct(){
		$this->dir = Zend_Controller_Front::getInstance()->getBaseUrl() . '/../logs/';
		$this->login = Zend_Auth::getinstance()->getStorage()->read()->dane->login;
	}
	public function login(){
		$dir = '../logs/login/';
		$file = $dir . date('Y.m') . '.login.txt';
		
		$fd = fopen($file, 'a');
		
		if(flock($fd, LOCK_EX)){
			fputs($fd, date('Y.m.d H:i:s') . ";" . $this->login . ";" . $_SERVER['REMOTE_ADDR'] . "\n");
			flock($fd, LOCK_UN);
		}
		fclose($fd);
	}
	public function logout(){
		$dir = '../logs/login/';
		$file = $dir . date('Y.m') . '.logout.txt';
		
		$fd = fopen($file, 'a');
		
		if(flock($fd, LOCK_EX)){
			fputs($fd, date('Y.m.d H:i:s') . ";" . $this->login . ";" . $_SERVER['REMOTE_ADDR'] . "\n");
			flock($fd, LOCK_UN);
		}
		fclose($fd);
	}
}
